package com.hdoit.ares.logical.share.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.acc.service.IGoldenBeanDetailService;
import com.hdoit.ares.logical.share.dao.IShareStudyDao;
import com.hdoit.ares.logical.share.model.ShareStudy;
import com.hdoit.ares.logical.share.service.IShareStudyService;
import com.hdoit.ares.selfcommon.enums.acc.GoldenBeanType;
import com.hdoit.ares.selfcommon.enums.acti.TaskId;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.common.utils.CommonUtils;
import com.tennetcn.common.utils.DateUtils;
/**
 * @author      caochengmeng
 * @email       
 * @createtime  2018年04月02日 08:38:49
 * @comment
 */
@Component
public class ShareStudyServiceImpl extends SuperService<ShareStudy> implements IShareStudyService{

	private IGoldenBeanDetailService goldenBeanDetailService;
	private IShareStudyDao shareStudyDao;
	
	public IGoldenBeanDetailService getGoldenBeanDetailService() {
		return goldenBeanDetailService;
	}
	@Resource
	public void setGoldenBeanDetailService(IGoldenBeanDetailService goldenBeanDetailService) {
		this.goldenBeanDetailService = goldenBeanDetailService;
	}
	public IShareStudyDao getShareStudyDao() {
		return shareStudyDao;
	}
	@Resource
	public void setShareStudyDao(IShareStudyDao shareStudyDao) {
		this.shareStudyDao = shareStudyDao;
	}

	@Override
	public int queryCountVideos(String customerId, String studyType) {
		return shareStudyDao.queryCountVideos(customerId, studyType);
	}
	
	
	@Override
	public boolean setStudyVideos(String studyId, String studyType, String customerId) {
		ShareStudy shareStudy = new ShareStudy();
		shareStudy.setId(CommonUtils.getKeyId());
		shareStudy.setStudyId(studyId);
		shareStudy.setStudyType(studyType);
		shareStudy.setCustomerId(customerId);
		shareStudy.setCreateTime(DateUtils.getCurrent());
		shareStudy.setModelStatus(ModelStatus.add);
		if(applyChange(shareStudy)){
			return true;
		}
		if(queryCountVideos(customerId,studyType)==3){
			goldenBeanDetailService.addGoldenBeanDetail(TaskId.weekStudy, 100, GoldenBeanType.weekStudy, customerId);
		}
		return false;
	}
	@Override
	public boolean queryIsCountVideos(String customerId, String studyType) {
		if(queryCountVideos(customerId, studyType)>=3){
			return true;
		}
		return false;
	}

}